// 导入各个组件
import Vue from 'vue'
import Router from 'vue-router'
// 主页
import Home from '../page/Home.vue'
// 方案
import Project from '../page/ProjectClass/Project.vue'
import ProjectClass from '../page/ProjectClass/children/ProjectClass.vue'
import ProjectSearch from '../page/ProjectClass/children/ProjectSearch.vue'
import ProjectDetail from '../page/ProjectClass/children/ProjectDetail.vue'
// 用户
import UsersHome from '../page/Users/UsersHome.vue'
import Login from '../page/Users/children/Login.vue'
import SignUp from '../page/Users/children/SignUp.vue'
// 客服
import Service from '../page/Service/Service.vue'

// 使用路由
Vue.use(Router)

// 将路由导出
export default new Router({
  /**
   * 跳转路由时返回顶部
   */
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  },
  // 启用 history 模式
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [{
      path: '*',
      name: 'login',
      component: Login
    },
    {
      path: '/',
      name: 'home',
      component: Home
    },
    {
      path: '/users/:activeName',
      name: 'users',
      component: UsersHome,
      children: [{
          path: 'login',
          name: 'login',
          component: Login
        },
        {
          path: 'signup',
          name: 'signup',
          component: SignUp
        }
      ]
    },
    {
      path: '/projectclass',
      name: 'projectclass',
      component: Project,
      children: [{
          path: ':class',
          name: 'class',
          component: ProjectClass
        },
        {
          path: 'search/:keyword',
          name: 'search',
          component: ProjectSearch
        },
        {
          path: 'projectdetail/:project_id',
          name: 'projectdetail',
          component: ProjectDetail
        }
      ]
    },
    {
      path: '/service',
      name: 'service',
      component: Service
    },
  ]
})